package com.mall.controller;

import com.mall.dto.FlashProductRelationUpdateDto;
import com.mall.pageResult.PageResult;
import com.mall.pojo.SmsFlashPromotionProductRelation;
import com.mall.service.FlashProductRelationService;
import com.mall.utils.Result;
import com.mall.vo.FlashProductRelationListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/flashProductRelation")
public class FlashProductRelationController {

    @Autowired
    private FlashProductRelationService relationService;

    /**
     * 分页查询不同场次关联及商品信息
     *
     * @param pageNum
     * @param pageSize
     * @param flashPromotionId        活动id
     * @param flashPromotionSessionId 场次id
     * @return
     */
    @GetMapping("/list")
    public Result<PageResult<FlashProductRelationListVo>> list(@RequestParam(value = "pageNum", required = false) Integer pageNum,
                                                               @RequestParam(value = "pageSize", required = false) Integer pageSize,
                                                               @RequestParam(required = false) Integer flashPromotionId,
                                                               @RequestParam(required = false) Integer flashPromotionSessionId) {
        PageResult<FlashProductRelationListVo> result = relationService.list(pageNum, pageSize, flashPromotionId, flashPromotionSessionId);
        return Result.success(result,"操作成功");
    }

    /**
     * 修改秒杀关联信息
     * @param id
     * @param relation
     * @return
     */
    @PostMapping("/update/{id}")
    public Result<Integer> update(@PathVariable Integer id,@RequestBody FlashProductRelationUpdateDto relation){
        Integer count = relationService.update(relation);
        return Result.success(count,"操作成功");
    }

    /**
     * 批量选择商品添加关联
     * @param relationList
     * @return
     */
    @PostMapping("/create")
    public Result<Integer> create(@RequestBody List<SmsFlashPromotionProductRelation> relationList){
        Integer count = relationService.create(relationList);
        return Result.success(count,"操作成功");
    }

    /**
     * 删除关联
     * @param id
     * @return
     */
    @PostMapping("/delete/{id}")
    public Result<Integer> delete(@PathVariable Integer id){
        Integer count = relationService.delete(id);
        return Result.success(count,"操作成功");
    }

    //todo:获取管理商品促销信息  /flashProductRelation/{id}
}
